package com.mayikt.member.impl.mapper;

import com.mayikt.member.impl.entitydo.UserDo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

public interface UserMapper {

    @Insert("INSERT INTO meite_user(MOBILE, PASSWORD, CREATE_TIME) VALUES (#{mobile}, #{passWord}, now())")
    int register(UserDo userDo);

    @Select("SELECT user_id      AS userid,\n" +
            "       mobile       AS mobile,\n" +
            "       password     AS password,\n" +
            "       user_name    AS username,\n" +
            "       user_name    AS username,\n" +
            "       sex          AS sex,\n" +
            "       age          AS age,\n" +
            "       create_time  AS createtime,\n" +
            "       is_available AS isavailable,\n" +
            "       pic_img      AS picimg,\n" +
            "       qq_openid    AS qqopenid,\n" +
            "       wx_openid    AS wxopenid\n" +
            "FROM meite_user\n" +
            "WHERE mobile = #{mobile} AND password = #{passWord}")
    UserDo login(String mobile, String passWord);

    @Select("SELECT user_id      AS userid,\n" +
            "       mobile       AS mobile,\n" +
            "       password     as password,\n" +
            "       user_name    as username,\n" +
            "       sex          as sex,\n" +
            "       age          as age,\n" +
            "       create_time  as createtime,\n" +
            "       is_available as isavailable,\n" +
            "       pic_img      as picimg,\n" +
            "       qq_openid    as qqopenid,\n" +
            "       wx_openid    as wxopenid\n" +
            "from meite_user\n" +
            "where mobile = #{mobile}")
    UserDo existMobile(String mobile);

    @Select("SELECT user_id      AS userid,\n" +
            "       mobile       AS mobile,\n" +
            "       password     AS password,\n" +
            "       user_name    AS username,\n" +
            "       sex          AS sex,\n" +
            "       age          AS age,\n" +
            "       create_time  AS createtime,\n" +
            "       is_available AS isavailable,\n" +
            "       pic_img      AS picimg,\n" +
            "       qq_openid    AS qqopenid,\n" +
            "       wx_openid    AS wxopenid\n" +
            "FROM meite_user\n" +
            "WHERE user_id =#{userId}")
    UserDo findByUser(Long userId);


    @Update("update meite_user set WX_OPENID=#{wxOpenId} where user_id=#{userId}")
    int updateUseOpenId(@Param("userId") Long userId, @Param("wxOpenId") String wxOpenId);

    @Select("SELECT user_id      AS userid,\n" +
            "       mobile       AS mobile,\n" +
            "       password     AS password,\n" +
            "       user_name    AS username,\n" +
            "       sex          AS sex,\n" +
            "       age          AS age,\n" +
            "       create_time  AS createtime,\n" +
            "       is_available AS isavalible,\n" +
            "       pic_img      AS picimg,\n" +
            "       qq_openid    AS qqopenid,\n" +
            "       wx_openid    AS wxopenid\n" +
            "FROM meite_user\n" +
            "WHERE wx_openid =#{wxOpenId}")
    UserDo selectByOpenId(@Param("wxOpenId") String wxOpenId);


    @Update("update meite_user set WX_OPENID=null where WX_OPENID=#{wxOpenId}")
    int cancelFollowOpenId(@Param("wxOpenId") String wxOpenId);
}
